<template>
    <div class="widget-print" v-if="JSON.stringify(bill) !== '{}'">
        <div class="print-bill" id="printArea">
            <div class="bill-head">
                <img class="head-logo" :src="bill.carrierLogo" alt="" />
            </div>
            <div class="bill-info">
                <div class="info-code">
                    <span>{{ bill.basDnBSortingDataDto.endRdcShortCode }}</span>
                    <span>{{ bill.basDnBSortingDataDto.siteShortCode }}</span>
                    <span>{{ bill.basDnBSortingDataDto.siteAreaCode }}</span>
                </div>
                <div class="info-barcode">
                    <div class="barcode-box">
                        <svg id="barcode1"></svg>
                    </div>
                </div>
                <div class="info-c">
                    <div class="c-left">
                        <div class="left-info">
                            <div class="info-rdc">
                                <p class="rdc-item first">
                                    <span class="name">{{ bill.basDnBSortingDataDto.firstRdcShortName }}</span>
                                    <span class="code">{{ bill.basDnBSortingDataDto.firstRdcShortCode }}</span>
                                </p>
                                <p class="rdc-item end">
                                    <span class="name">{{ bill.basDnBSortingDataDto.endRdcShortName }}</span>
                                    <span class="code">{{ bill.basDnBSortingDataDto.endRdcShortCode }}</span>
                                </p>
                            </div>
                            <div class="info-site">
                                <p class="site-item site">
                                    <span class="item-tag">末</span>
                                    <span class="item-value">{{ bill.basDnBSortingDataDto.siteName }}</span>
                                </p>
                                <p class="site-item aoi">
                                    <span class="item-tag">AOI</span>
                                    <span class="item-value">{{ bill.basDnBSortingDataDto.aoiCommunityName }}</span>
                                </p>
                            </div>
                        </div>
                        <div class="left-number">
                            <span class="number-tag">智能号码</span>
                            <span class="number-value"></span>
                        </div>
                        <div class="left-address from">
                            <div class="people">
                                <i class="iconfont admin-icon-shou"></i>
                                <span class="name bold">{{ bill.basDnBUseAddressReceiverESDto.receiverName }}</span>
                                <span class="mobile bold">{{ bill.basDnBUseAddressReceiverESDto.receiverMobile }}</span>
                            </div>
                            <div class="address">{{ bill.basDnBUseAddressReceiverESDto.receiverProvince }}{{ bill.basDnBUseAddressReceiverESDto.receiverCity }}{{ bill.basDnBUseAddressReceiverESDto.receiverArea }}{{ bill.basDnBUseAddressReceiverESDto.receiverDistrict }}{{ bill.basDnBUseAddressReceiverESDto.receiverAddress }}</div>
                            <div class="other">
                                <span class="time">{{ bill.createTime | iso8601DateTimeFormat('YYYY/MM/DD HH:mm:ss') }}</span>
                                <span class="check">已验视</span>
                                <span class="progress">1/100</span>
                            </div>
                        </div>
                        <div class="left-address to">
                            <div class="people">
                                <i class="iconfont admin-icon-ji"></i>
                                <span class="name bold">{{ bill.basDnBUseAddressSenderESDto.senderName }}</span>
                                <span class="mobile bold">{{ bill.basDnBUseAddressSenderESDto.senderMobile }}</span>
                            </div>
                            <div class="address" v-if="userInfo.companyId !== 11">{{ bill.basDnBUseAddressSenderESDto.senderProvince }}{{ bill.basDnBUseAddressSenderESDto.senderCity }}{{ bill.basDnBUseAddressSenderESDto.senderArea }}{{ bill.basDnBUseAddressSenderESDto.senderDistrict }}{{ bill.basDnBUseAddressSenderESDto.senderAddress }}</div>
                            <div class="address" v-else>{{ bill.basDnBUseAddressSenderESDto.senderProvince }}{{ bill.basDnBUseAddressSenderESDto.senderCity }}{{ bill.basDnBUseAddressSenderESDto.senderArea }}{{ bill.basDnBUseAddressSenderESDto.senderDistrict }}黄山村</div>
                        </div>
                    </div>
                    <div class="c-right">
                        <div class="barcode-box">
                            <svg id="barcode2"></svg>
                        </div>
                    </div>
                </div>
                <div class="info-foot">
                    <template v-if="bill.basDnBGoodsItemESDtos && bill.basDnBGoodsItemESDtos.length">
                        <p v-for="(item, index) in bill.basDnBGoodsItemESDtos" :key="index">
                            <span>{{item.itemName}}*{{item.itemNum}}</span>
                            <span v-if="index < bill.basDnBGoodsItemESDtos.length - 1">，</span>
                        </p>
                    </template>
                </div>
            </div>
        </div>
        <div class="print-footer">
            <el-button @click="cancelPrint">取 消</el-button>
            <el-button type="primary" v-print="print">确 定</el-button>
        </div>
    </div>
</template>

<script>
import JsBarcode from 'jsbarcode'
import { mapGetters } from 'vuex'
export default {
    name: 'WidgetPrint',
    computed: {
        ...mapGetters(['userInfo'])
    },
    props: {
        bill: {
            type: Object,
            default: () => ({})
        }
    },
    data() {
        const that = this
        return {
            print: {
                id: 'printArea',
                popTitle: '', // 打印配置页上方标题
                // 开启打印前的回调事件
                beforeOpenCallback() {
                    console.log('开启打印前')
                },
                // 调用打印之后的回调事件
                openCallback() {
                    console.log('调用打印之后');
                },
                //关闭打印的回调事件（无法确定点击的是确认还是取消）
                closeCallback() {
                    console.log('关闭打印');
                    that.$emit('closePrint')
                }
            },
        };
    },
    methods: {
        // 初始化条形码
        initBarCode() {
            JsBarcode("#barcode1", this.bill.mailNo, {
                fORMat: "CODE128",
                width: 2,
                height: 58,
                margin: 2,
                textAlign: 'center',
                textMargin: -3,
                fontSize: 18,
                fontOptions: 'bold',
            })

            JsBarcode("#barcode2", this.bill.mailNo, {
                fORMat: "CODE128",
                width: 1.5,
                height: 58,
                margin: 2,
                textMargin: -3,
                fontSize: 18,
                fontOptions: 'bold',
            })
        },
        // 关闭打印
        cancelPrint() {
            this.$emit('cancelPrint')
        }
    },
    mounted() {

    },
};
</script>

<style lang="scss" scoped>
// 背景色加该属性
//  -webkit-print-color-adjust: exact;

@page {
    size: auto;
    margin: 0mm;
}

.print-bill {
    width: 379px;
    height: 645px;
    font-family: sans-serif;
    color: #000000;
    border: 1px solid #000000;
    margin: 0 auto;
    .bill-head {
        width: 370px;
        height: 50px;
        margin: 0 auto;
        .head-logo {
            width: auto;
            height: 50px;
        }
    }
    .bill-info {
        width: 370px;
        height: 529px;
        margin: 0 auto;
        border: 2px solid #000000;
        border-radius: 2px;
        display: flex;
        flex-direction: column;
        .info-code {
            height: 60px;
            border-bottom: 2px solid #000000;
            display: flex;
            justify-content: space-around;
            font-size: 46px;
            font-weight: bold;
        }
        .info-barcode {
            height: 84px;
            border-bottom: 2px solid #000000;
            .barcode-box {
                text-align: center;
                margin: 0 auto;
            }
        }
        .info-c {
            flex: 1;
            border-bottom: 2px solid #000000;
            display: flex;
            justify-content: space-between;
            .c-left {
                flex: 1;
                border-right: 2px solid #000000;
                .left-info {
                    height: 78px;
                    display: flex;
                    align-items: center;
                    border-bottom: 1px solid #000000;
                    .info-rdc {
                        width: 122px;
                        height: 100%;
                        display: flex;
                        justify-content: space-between;
                        .rdc-item {
                            flex: 0 0 50%;
                            display: flex;
                            flex-direction: column;
                            font-weight: bold;
                            .name {
                                height: 28px;
                                font-size: 18px;
                                display: flex;
                                justify-content: center;
                                align-items: center;
                            }
                            .code {
                                flex: 1;
                                font-size: 24px;
                                display: flex;
                                justify-content: center;
                                align-items: center;
                                border-top: 1px dashed #000000;
                            }

                            &:nth-child(1) {
                                border-right: 1px dashed #000000;
                            }
                        }
                    }
                    .info-site {
                        flex: 1;
                        height: 100%;
                        border-left: 1px solid #000000;
                        display: flex;
                        flex-direction: column;
                        .site-item {
                            flex: 0 0 50%;
                            display: flex;
                            align-items: center;
                            padding: 0 4px;
                            overflow: hidden;
                            &:nth-child(1) {
                                border-bottom: 1px solid #000000;
                            }
                            .item-tag {
                                padding: 3px;
                                color: #ffffff;
                                font-size: 13px;
                                font-weight: bold;
                                background-color: #000000;
                                -webkit-print-color-adjust: exact;
                            }
                            .item-value {
                                margin-left: 10px;
                                font-size: 16px;
                                font-weight: bold;
                            }
                        }
                    }
                }
                .left-number {
                    height: 30px;
                    border-bottom: 1px solid #000000;
                    display: flex;
                    align-items: center;
                    .number-tag {
                        width: 70px;
                        height: 100%;
                        color: #ffffff;
                        font-size: 14px;
                        font-weight: bold;
                        background-color: #000000;
                        -webkit-print-color-adjust: exact;
                        display: flex;
                        align-items: center;
                        justify-content: center;
                    }
                    .number-value {
                        font-size: 16px;
                        font-weight: bold;
                        padding-left: 10px;
                    }
                }
                .left-address {
                    padding: 0px 6px 8px 6px;
                    display: flex;
                    flex-direction: column;
                    justify-content: space-between;
                    &.from {
                        min-height: 105px;
                        max-height: 150px;
                        .people {
                            .iconfont {
                                font-size: 30px;
                            }
                        }
                    }
                    &.to {
                        border-top: 2px solid #000000;
                        .people {
                            .iconfont {
                                font-size: 26px;
                                font-weight: normal;
                            }
                        }
                    }
                    .people {
                        display: flex;
                        align-items: center;
                        .name {
                            font-size: 16px;
                            margin-left: 16px;
                        }
                        .mobile {
                            font-size: 16px;
                            margin-left: 16px;
                        }
                        .bold {
                            font-weight: bold;
                        }
                    }
                    .address {
                        font-size: 16px;
                        font-weight: bold;
                        text-align: left;
                    }
                    .other {
                        font-size: 15px;
                        display: flex;
                        justify-content: space-between;
                        .check {
                            font-weight: bold;
                        }
                        .progress {
                            font-weight: bold;
                        }
                    }
                }
            }
            .c-right {
                height: 100%;
                width: 78px;
                .barcode-box {
                    margin-top: 60px;
                    margin-right: 2px;
                    text-align: center;
                    transform: rotateZ(90deg);
                }
            }
        }
        .info-foot {
            height: 114px;
            padding: 2px;
            display: flex;
            flex-wrap: wrap;
        }
    }
}
.print-footer {
    padding: 10px 0px 0px 0px;
    margin-top: 16px;
    border-top: 1px solid #ebeef5;
    display: flex;
    justify-content: flex-end;
}
</style>